package com.qianclass.talklive.app.im;
import java.util.LinkedList;
import java.util.Queue;

public class DataPool {
	class DataBuffer
	{
		private byte[] buf;
		private int len;
		public DataBuffer(byte[] data, int nLen)
		{
			len = nLen;
			buf = new byte[len];
			System.arraycopy(data,0,buf,0,nLen);
		}
		public byte[] GetBuffer()
		{
			return buf;
		}
		public int GetLength()
		{
			return len;
		}
	}

	private Queue<DataBuffer> storage =  new LinkedList<DataBuffer>();

	public void push_back(byte[] data, int nLen)
	{
		synchronized(storage)
		{
			DataBuffer obj = new DataBuffer( data, nLen );
			storage.add(obj);
		}
	}

	public DataBuffer pop_front()
	{
		synchronized(storage)
		{
			if(!storage.isEmpty())
			{
				return storage.remove();
			}
			return null;
		}
	}
}
